package day07;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Stream;

public class homework04 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入需要加密的字符串：");
        String str = sc.nextLine();
        String locked=lock(str);
        System.out.println(locked);
    }

    private static String lock(String str) {
        Map<String, String> map = new HashMap<>();
        map.put("abc", "2");
        map.put("def", "3");
        map.put("ghi", "4");
        map.put("jkl", "5");
        map.put("mno", "6");
        map.put("pqrs", "7");
        map.put("tuv", "8");
        map.put("wxyz", "9");
        String last = "";
        for (int i = 0; i < str.length(); i++) {
            char strs = str.charAt(i);
            if (strs >= 60 && strs <= 90) {
                strs += 33;
                last += String.valueOf(strs);
            } else if (strs >= 97 && strs <= 122) {
                Set<Map.Entry<String, String>> entries = map.entrySet();
                for (Map.Entry<String, String> e1:entries) {
                    if (e1.getKey().contains(String.valueOf(strs))) {
                        last += e1.getValue();
                    }
                }

            } else {
                last += String.valueOf(strs);
            }
        }
       return last;
    }
}
